package enrique.kurso.tablet.fragments;

import java.util.ArrayList;
import java.util.List;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.app.ListFragment;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import enrique.kurso.R;
import enrique.kurso.lecionoj.Leciono0101;
import enrique.kurso.lecionoj.Leciono0102;
import enrique.kurso.lecionoj.Leciono0103;
import enrique.kurso.lecionoj.Leciono0104;
import enrique.kurso.lecionoj.Leciono0106;
import enrique.kurso.lecionoj.VortoLudo;
import enrique.kurso.tablet.MenuFragment;
import enrique.kurso.tablet.MultiPaneActivity;
import enrique.kurso.util.ProgressView;

public class Leciono01Fragment  extends ListFragment {
	private ListAdapter m_adapter;
	
	@Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
      
        List<String> options=new ArrayList<String>();
        options.add(getResources().getString(R.string.alfabeto));
        options.add(getResources().getString(R.string.comprensionAuditiva));
        options.add(getResources().getString(R.string.pronombresPersonales));
        options.add(getResources().getString(R.string.verbos));
        options.add(getResources().getString(R.string.glosario));
        options.add(getResources().getString(R.string.plural));
        options.add(getResources().getString(R.string.pronombresPosesivos));
        options.add(getResources().getString(R.string.articulo));
        options.add(getResources().getString(R.string.frases));
        options.add(getResources().getString(R.string.vortoLudo));
        options.add(getResources().getString(R.string.traduzcaEsperanto));
        
        this.m_adapter = new ListAdapter(this.getActivity(), R.layout.leciono,options);
        setListAdapter(this.m_adapter);
	}
	@Override
    public void onListItemClick(ListView l, View v, int position, long id) {
    	FragmentManager fragmentManager = getFragmentManager();
		FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    	switch (position) {
		case 0:
			
			Fragment fragmentD = getFragmentManager().findFragmentByTag("menuFragment");
			fragmentTransaction.remove(fragmentD);
			fragmentD = getFragmentManager().findFragmentByTag("leccionMenuFragment");
			fragmentTransaction.remove(fragmentD);
			fragmentTransaction.replace(R.id.left_pane, new Leciono01Fragment());
			
			MenuFragment fragment = new MenuFragment();
			fragmentTransaction.add(R.id.right_pane, fragment);
			fragmentTransaction.commit();
			break;
		case 1:
			MenuFragment menuFragment = new MenuFragment();
			fragmentTransaction.add(R.id.right_pane, menuFragment);
			fragmentTransaction.commit();
			break;
		case 2:
			
			break;
		case 3:
		
			break;
		case 4:
			
			break;
		case 5:
		
		default:
			break;
		}
  
    }
	
	@Override
	public void onResume() {
		   super.onResume();
		   ((ListAdapter) this.getListAdapter()).notifyDataSetChanged();
	    }
	

	   private class ListAdapter extends ArrayAdapter<String> {

	        private List<String> items;
	        private Context context;

	        public ListAdapter(Context context, int textViewResourceId, List<String> items) {
	                super(context, textViewResourceId, items);
	                this.items = items;
	                this.context = context;
	        }

	        public void setItems(List<String> items) {
	                this.items = items;
	                
	        }
	        
	        @Override
	        public View getView(int position, View convertView, ViewGroup parent) {
	                View v = convertView;
	                if (v == null) {
	                    LayoutInflater vi = (LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	                    v = vi.inflate(R.layout.leciono, null);
	                }
	                String titulo = items.get(position);
	                if (titulo!=null) {
	                        TextView tt = (TextView) v.findViewById(R.id.toptext);
	                        if (tt != null) {
	                              tt.setText(titulo);
	                        }

	                     
	                    
	                        ImageView exercise = (ImageView) v.findViewById(R.id.exerciseDone);
	                }
	                return v;
	        }
	}
	   
	  
}
